/*
 * @Descripttion:
 * @Author: cuidm
 * @Date: 2022-03-31 14:58:28
 * @LastEditors: cuidm
 * @LastEditTime: 2022-10-11 14:45:56
 */
import React, { useState, useEffect, Fragment } from 'react';
import { message } from 'antd';
import { HcpTipModal } from '@/components';
import cmdbres from '@/data/cmdbres';
import request from '@/utils/request';
import hcpUtils from '@/utils/hcpUtils';

const user = hcpUtils.getUser();
const DeleteModel = ({ info, visible, setVisible, onDeleteFinish }) => {
    const [loading, setLoading] = useState(false);

    const onFinish = async () => {
        try {
            setLoading(true);
            let res = await request({
                ...cmdbres.deleteModel(info.cmModuleId),
                params: {
                    author: user.staffName,
                },
                headers: {
                    id: info.cmModuleId,
                },
            });
            setVisible(false);
            if (res && res.code == 200) {
                message.success('删除成功！');
                if (typeof onDeleteFinish == 'function') onDeleteFinish(res);
            } else {
                if (res) message.error(res.msg);
            }
        } catch (err) {
            // ...
        } finally {
            setLoading(false);
        }
    };

    return (
        <HcpTipModal
            title={`删除${info?.moduleName}`}
            visible={visible}
            loading={loading}
            onFinish={onFinish}
            onCancel={() => {
                setVisible(false);
            }}
            content={
                <>
                    <div className="main-content">
                        <span className="main-content-info">
                            确定要删除模型
                            <span style={{ color: '#4E84E9' }}>{info?.moduleName}</span>？
                        </span>
                    </div>
                </>
            }
        />
    );
};

export default DeleteModel;
